<template>
  <!-- 选择任务箱 -->
  <view class="task-item-box" @click="cancel">
    <view class="task-item-info" @click.stop="">
      <view class="task-info-head">选择任务箱</view>
      <radio-group>
        <view class="task-info-body">
          <scroll-view scroll-y>
            <view
              class="task-info-item"
              v-for="(item, index) in taskTypeList"
              :key="item.oid"
              @click="selectRadio(index)"
            >
              <span class="task-item-text">{{ item.o_text }}</span>
              <radio :checked="currentRadio == index ? true : false" />
              <image
                class="task-item-icon"
                :src="item.option.icon"
                mode="widthFix"
              />
            </view>
          </scroll-view>
        </view>
      </radio-group>
      <view class="task-info-foot">
        <span @click="cancel">取消</span>
        <span @click="getTaskItem">确定</span>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    taskTypeList: {
      type: Array,
      default: [],
    },
    taskTypeId: {
      type: String,
      default: "",
    },
  },
  components: {},
  data() {
    return {
      currentRadio: 0,
      taskInfo: {},
    };
  },
  computed: {},
  watch: {},
  methods: {
    cancel() {
      this.$emit("cancel");
    },
    getTaskItem() {
      this.$emit("getTaskItem", this.taskInfo);
    },
    selectRadio(index) {
      this.currentRadio = index;
      this.taskInfo = this.taskTypeList[index];
    },
  },
  created() {},
  mounted() {
    if (this.taskTypeId != "") {
      this.currentRadio = this.taskTypeList.findIndex(
        item => item.oid == this.taskTypeId
      );
      this.taskInfo = this.taskTypeList[this.currentRadio];
    } else {
      this.taskInfo = this.taskTypeList[0];
    }
  },
  beforeDestroy() {},
};
</script>

<style lang="scss" scoped>
// 选择任务箱
.task-item-box {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 10;

  .task-item-info {
    position: absolute;
    left: 4%;
    bottom: 4%;
    width: 92%;
    padding: 30rpx 0;
    background-color: #fff;
    border-radius: 8rpx;
    color: #333;
    font-size: 28rpx;

    .task-info-head {
      height: 44rpx;
      padding-left: 30rpx;
      color: #333;
      font-size: 32rpx;
      font-weight: bold;
    }

    .task-info-body {
      display: flex;
      flex-direction: column;
      align-items: center;
      height: auto;
      max-height: 660rpx;
      margin-top: 30rpx;
      margin-bottom: 60rpx;
      margin-left: 30rpx;

      .task-info-item {
        position: relative;
        display: flex;
        justify-content: space-between;
        width: 90%;
        margin-top: 30rpx;
        margin-left: 10%;
        padding-right: 32rpx;
        padding-bottom: 30rpx;
        border-bottom: 2rpx solid #f2f2f2;

        .task-item-icon {
          position: absolute;
          top: 0;
          left: -10%;
          width: 40rpx;
          height: 40rpx;
        }

        .task-item-text {
          flex: 1;
        }
      }
    }

    .task-info-foot {
      position: relative;
      height: 56rpx;

      &::before {
        content: "";
        position: absolute;
        top: 2rpx;
        left: 50%;
        width: 2rpx;
        height: 48rpx;
        background-color: #cccccc;
        transform: translateX(-50%);
      }

      & span {
        display: inline-block;
        width: 50%;
        height: 52rpx;
        line-height: 52rpx;
        text-align: center;
        font-size: 28rpx;
        color: #999999;
      }

      & span:last-child {
        color: #666ee8;
      }
    }
  }
}

scroll-view {
  height: auto;
  max-height: 660rpx;
}
</style>
